<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>用户登陆成功</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	<link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="css/plugins/clockpicker/clockpicker.css" rel="stylesheet">   
    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
  </head>
  <body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>轮播图</h5>
                </div>
                <div class="ibox-content">
                        <div class="input-group">
                            <button class="btn btn-primary" type="button" style="margin-bottom: 0px;"
                                    onclick="addCarouselInfo();"><i class="glyphicon glyphicon-plus"></i>&nbsp;新增幻灯片
                            </button>
                        </div>  
                </div> 
            </div>
        </div>
    </div>
    <!-- Panel Other -->
    <div class="ibox float-e-margins" id="tableShow">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <table id="CarouselInfoListTable" data-mobile-responsive="true"
                               data-click-to-select="true" data-unique-id="id">
                            <thead>
                            </thead>
                        </table>
                    </div>
                </div>
                <!-- End Example Events -->
            </div>
        </div>
    </div>
    <div style="display: none;position: relative;
    top: -50px;" class="modal" id="myModal" tabindex="-1"role="dialog" aria-labelledby="myModalLable" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <%--<button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>--%>
                <h4 class="modal-title" id="myModallabel">消息提示</h4>
            </div>
            <div class="modal-body">
                是否删除<span id="deletecontent"></span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="confirm" onclick="confirm()">确定删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" id="cancel" onclick="cancel()">取消删除</button>

            </div>
        </div>
    </div>
</div>
</div>


<!-- End Panel Other -->
</div>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--时间选择-->
<script src="js/plugins/layer/laydate/laydate.js"></script>
<!--下拉框-->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script>
    function addCarouselInfo(){
    	 window.location.href="<%=basePath%>carouselInfo/openCarouselInfo"; 
    }
    var $table = $('#CarouselInfoListTable');

    var search = function () {
        $table.bootstrapTable('refresh');
    }
    var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };

    $(document).ready(function () {
        //将表单元素和table属性转成json
        queryParams = function (params) {
            var temp = {};
            temp.currentResult = params.offset;
            temp.showCount = params.limit;
            var formParam = $('#queryForm').serializeArray();
            for (var i = 0; i < formParam.length; i++) {
                if (formParam[i].value != '') {
                    temp[formParam[i].name] = formParam[i].value;
                }
            }
            return temp;
        };


        detailFormatter = function (index, row) {
            var html = [];
            if (row.username) {
                html.push('<p><b>用户名:</b> ' + row.username + '</p>');
            }
            if (row.mobile) {
                html.push('<p><b>手机:</b> ' + row.mobile + '</p>');
            }
            if (row.email) {
                html.push('<p><b>邮箱:</b> ' + row.email + '</p>');
            }
            if (row.realname) {
                html.push('<p><b>真实姓名</b> ' + row.realname + '</p>');
            }
            if (row.companyname) {
                html.push('<p><b>公司名:</b> ' + row.companyname + '</p>');
            }
            return html.join('');
        }

        rowStyle = function (row, index) {
            var classes = ['active', 'success', 'info', 'warning', 'danger'];
            if (index % 2 === 0 && index / 2 < classes.length) {
                return {
                    classes: classes[index / 2]
                };
            }
            return {};
        }

        $table.bootstrapTable({
            url: "carouselInfo/getCarouselInfoList",
            pagination: !0,
            showRefresh: !0,
            showToggle: !0,
            showColumns: !0,
            iconSize: "outline",
            striped: true, //是否显示行间隔色
            queryParams: queryParams,//传递参数（*）
            sidePagination: "server", //服务端处理分页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [5, 10, 20, 50],        //可供选择的每页的行数（*）
            minimunCountColumns: 2,      //可供选择的每页的行数（*）
            //detailView: true,
            sortName: undefined,
            sortOrder: 'asc',
            sortStable: false,
            type: "post",
            contentType: "application/json; charset=utf-8",
            detailFormatter: detailFormatter,
            rowStyle: rowStyle,
            iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
            icons: {
                refresh: "glyphicon-repeat",
                toggle: "glyphicon-list-alt",
                columns: "glyphicon-list",
                detailOpen: 'glyphicon-plus icon-plus',
                detailClose: 'glyphicon-minus icon-minus',
                sortable: 'glyphicon-minus icon-minus'
            },
            onLoadSuccess: function (data) {
                if (data.total < 5) {
                    $table.bootstrapTable('getOptions')["height"] = 400;
                } else {
                    $table.bootstrapTable('getOptions')["height"] = '';
                }

                $table.bootstrapTable('hideColumn', 'id');
                $table.bootstrapTable('hideColumn', 'edit');
            },
            columns: [
                {
                    title: '显示顺序',
                    field: 'sort',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '标题',
                    field: 'name',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '图片',
                    field: 'img',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {                        	
                    	return '<img src="'+value+'" style="width:36px;height:36px;"/>';                    
                    }
                },
                {
                    title: '链接',
                    field: 'picUrl',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    width : '140',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                          return '<a><button class="btn  btn-xs" id="editButton" onclick="editCarouselInfoDetail(\''+row.id+'\','+index+')" title="修改"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button></a>'+
                                '&nbsp;<a><button class="btn  btn-xs" onclick="delete_tr(this,\''+row.id+'\')" title="删除"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></a>';

                    }
                }
                
            ]
        });
        for (var selector in config)$(selector).chosen(config[selector]);
    });

    function tableHeight() {
        return $(window).height() - 50;
    }
    var delete_tr_id = null;
    function delete_tr(a) {
        var s = $(a).parent().parent().parent().children().eq(1).text();
        delete_tr_id = $(a).parent().parent().parent().attr("data-uniqueid");
        $("#deletecontent").html(s);
        $("#tableShow").hide();
        $("#myModal").show();
    }
    function cancel() {
        $("#tableShow").show();
        $("#myModal").hide();
    }
    function confirm() {
        $.ajax({
            url: "<%=basePath%>carouselInfo/deleteCarouselInfo",
            type: "post",
            data: {"id": delete_tr_id},
            dataType: "json",
            success: function (note) {
                $("#tableShow").show();
                $("#myModal").hide();
                $table.bootstrapTable('refresh');
            },
            error: function () {
                alert("删除异常，请稍后重试");
            }

        });
    }
    //修改数据
    function editCarouselInfoDetail(id, index){
		window.location.href = "<%=basePath%>carouselInfo/updateCarouselInfo.do?id="+id; 
    }
</script>
  </body>
</html>
